package com.woniuxy.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class SwaggerConfig {
    @Autowired
    private SwaggerProperties swaggerProperties;
    @Bean
    public Docket createRestApi() {
        ApiInfoBuilder builder = new ApiInfoBuilder();
        builder.title(swaggerProperties.getTitle());
        builder.description(swaggerProperties.getDescription());
        builder.version(swaggerProperties.getVersion());
        builder.contact(new Contact(
                swaggerProperties.getName(),
                swaggerProperties.getAuthor(),
                swaggerProperties.getEmail()
        ));
        //构建API对象
        ApiInfo api = builder.build();
        //构建API清单 用于说明那些接口需要生成API文档
        Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(api);
        //定义接口（控制层）所在的包
        docket.select().apis(RequestHandlerSelectors.basePackage("com.woniuxy.controller")).paths(PathSelectors.any()).build();
        return docket;
    }
}
